home *** CD-ROM | disk | FTP | other *** search
- /****************************************************/
- /* Powerbook Screen Tester */
- /* */
- /* Initial Version - 6/10/93 */
- /* */
- /* Author: David M. Meleedy */
- /* dmm@head-cfa.harvard.edu */
- /****************************************************/
-
- #include <AppleEvents.h>
- #include <Values.h>
-
- #define kMoveToFront (WindowPtr)-1L
- #define kEmptyString "\p"
- #define kEmptyTitle kEmptyString
- #define kVisible true
- #define kNoGoAway false
- #define kNilRefCon (long) nil
- #define kSleep MAXLONG
- #define kHorizontalPixel 30
- #define kVerticalPixel 50
- #define kTextSize 20
-
- /***********************/
- /* GLOBALS */
- /***********************/
-
- short gOldMBarHeight;
- Boolean gDone;
-
- /***********************/
- /*** FUNCTIONS */
- /***********************/
-
- void ToolBoxInit ( void );
- void WindowInit ( void );
- void MainLoop ( void );
- void DoEvent ( EventRecord *eventPtr );
- void HandleKeyDown ( EventRecord *eventPtr );
- void HandleMouseDown ( void );
- void cycle_color ( void );
-
- void main ( void )
- {
- ToolBoxInit ();
- WindowInit ();
- MainLoop ();
- }
-
- void MainLoop ( void )
- {
-
- EventRecord event;
-
- gDone = false;
-
- while ( gDone == false )
- {
- if ( WaitNextEvent ( everyEvent, &event,
- kSleep, nil ) )
- DoEvent ( &event );
- }
-
- MBarHeight = gOldMBarHeight;
- ShowCursor();
- }
-
- void DoEvent ( EventRecord *eventPtr )
- {
- switch ( eventPtr->what )
- {
- case mouseDown:
- HandleMouseDown();
- break;
- case autoKey:
- case keyDown:
- HandleKeyDown( eventPtr );
- break;
- }
- }
-
- void HandleKeyDown ( EventRecord *eventPtr )
- {
- WindowPtr window;
- Rect windowRect;
- char thechar;
-
- thechar = eventPtr->message & charCodeMask;
-
- window = FrontWindow();
-
- windowRect.left = window->portRect.left;
- windowRect.right = window->portRect.right;
- windowRect.top = window->portRect.top;
- windowRect.bottom = window->portRect.bottom;
-
- switch ( thechar )
- {
- case 'r':
- case 'R':
- ForeColor ( redColor );
- break;
- case 'g':
- case 'G':
- ForeColor ( greenColor );
- break;
- case 'b':
- case 'B':
- ForeColor ( blueColor );
- break;
- case 'w':
- case 'W':
- ForeColor ( whiteColor );
- break;
- case ' ':
- ForeColor ( blackColor );
- break;
- case 'q':
- case 'Q':
- gDone = true;
- break;
- case '\r':
- cycle_color ();
- break;
- default:
- break;
- }
- PaintRect ( &windowRect );
- }
-
- void HandleMouseDown ( void )
- {
-
- gDone = true;
-
- }
-
- void cycle_color ()
- {
- static int the_color = 1;
-
- if ( the_color == 6 )
- the_color = 1;
-
- switch ( the_color )
- {
- case 1:
- ForeColor ( blackColor );
- break;
- case 2:
- ForeColor ( whiteColor );
- break;
- case 3:
- ForeColor ( redColor );
- break;
- case 4:
- ForeColor ( greenColor );
- break;
- case 5:
- ForeColor ( blueColor );
- break;
- }
- the_color++;
- }
-
- void ToolBoxInit ( void )
- {
- InitGraf ( &thePort );
- InitFonts ();
- InitWindows ();
- /* InitMenus ();
- TEInit();
- InitDialogs ( nil ); */
- InitCursor();
- }
-
- void WindowInit ( void )
- {
- Rect totalRect, mBarRect;
- RgnHandle mBarRgn;
- WindowPtr window;
- short fontNum;
-
- gOldMBarHeight = MBarHeight;
- MBarHeight = 0;
-
- HideCursor();
-
- window = NewWindow ( nil, &(screenBits.bounds),
- kEmptyTitle, kVisible, plainDBox, kMoveToFront,
- kNoGoAway, kNilRefCon );
-
- SetRect ( &mBarRect, screenBits.bounds.left,
- screenBits.bounds.top,
- screenBits.bounds.right,
- screenBits.bounds.top+gOldMBarHeight );
-
- mBarRgn = NewRgn();
- RectRgn ( mBarRgn, &mBarRect );
- UnionRgn ( window->visRgn, mBarRgn, window->visRgn );
- DisposeRgn ( mBarRgn );
- SetPort ( window );
- FillRect ( &(window->portRect), white );
-
- GetFNum ("\pTimes", &fontNum );
-
- if ( fontNum != 0)
- TextFont ( fontNum );
-
- TextSize ( kTextSize );
-
- MoveTo ( kHorizontalPixel, kVerticalPixel );
- DrawString ("\pkeys:");
- MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 2) + 2 );
- DrawString ("\p<r> red, <g> green, <b> blue");
- MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 3) + 2 );
- DrawString ("\p<w> white, <space> black");
- MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 5) + 2 );
- DrawString ("\p<return> cycle through colors");
- MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 7) + 2);
- DrawString ("\p<q> or [mouse_click] quit");
- MoveTo ( kHorizontalPixel, kVerticalPixel + (kTextSize * 11) + 2);
- DrawString ("\pWritten by David M. Meleedy.");
- }
-